package com.github.aloxc.plugin.restplus.utils;

import com.github.aloxc.plugin.restplus.common.Consts;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.project.ProjectKt;
import org.jetbrains.annotations.NotNull;

import java.text.SimpleDateFormat;
/**
 *
 * @author leero
 */
public interface ProjectUtil {
    ThreadLocal<SimpleDateFormat> SDF = new ThreadLocal<SimpleDateFormat>(){
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
        }
    };

    /**
     * 读取rest的存储目录
     * @param project
     * @return
     */
    static String getConfigStorePath(@NotNull Project project) {
        String historyRoot = ProjectKt.getStateStore(project).getDirectoryStorePath(true);
        return historyRoot;
    }

    /**
     * 读取rest的存储目录
     * @param project
     * @return
     */
    static String getHistoryStorePath(@NotNull Project project) {
        String historyRoot = ProjectKt.getStateStore(project).getDirectoryStorePath(true);
        historyRoot += Consts.HISTORY_REQUESTS_ROOT;
        return historyRoot;
    }

    /**
     * 读取rest url的存储目录
     * @param project
     * @param module
     * @param url
     * @param parentName
     * @return
     */
    static String getHistoryStorePath(@NotNull Project project, Module module, String parentName, String url) {
        String historyRoot = ProjectKt.getStateStore(project).getDirectoryStorePath(true);
        historyRoot += Consts.HISTORY_REQUESTS_ROOT;
        historyRoot += "/" + Md5Util.encriypt((parentName != null ? parentName:module.getName()) + "/" + url);
//        historyRoot += "/" + SDF.get().format(new Date()) + ".json";
        return historyRoot;
    }


}